using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using ComputerShopE3.Models;

namespace ComputerShopE3.Controllers
{
    public class DeliveryController : Controller
    {
        ComputerShopDBEntities1 _db = new ComputerShopDBEntities1();
        //
        // GET: /Delivery/

        public ActionResult Index()
        {
            return View(_db.PT_GIAO_HANG.ToList());
        }

        //
        // GET: /Delivery/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Delivery/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Delivery/Create

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create([Bind(Exclude="id")]PT_GIAO_HANG ptGiaoHangToCreate)
        {
            try
            {
                // TODO: Add insert logic here
                _db.AddToPT_GIAO_HANG(ptGiaoHangToCreate);
                _db.SaveChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Delivery/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View(_db.PT_GIAO_HANG.Where(pt=>pt.id == id).First());
        }

        //
        // POST: /Delivery/Edit/5

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(PT_GIAO_HANG ptghToEdit)
        {
            try
            {
                PT_GIAO_HANG originalPTGH = _db.PT_GIAO_HANG.Where(pt => pt.id == ptghToEdit.id).First();
                _db.ApplyPropertyChanges(originalPTGH.EntityKey.EntitySetName, ptghToEdit);
                _db.SaveChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
